/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.model;
/**
 * 说明：
 * 员工管理model
 * @Author：黄盛强
 * @Date：2012-03-20
 */
import java.util.List;
import java.util.Vector;

import javax.swing.table.AbstractTableModel;

import com.ruipengkj.ApplicationContext;
import com.ruipengkj.bean.TEmployee;
import com.ruipengkj.bean.TRole;

public class DataEmployeesModel extends AbstractTableModel {

	private static final long serialVersionUID = 1L;
	private Vector<List<Object>> rowdatas=new Vector<List<Object>>();
	private Vector<String> columns = new Vector<String>();
	public DataEmployeesModel(){
		columns.add("员工编号");
		columns.add("员工号");
		columns.add("员工角色");
		columns.add("员工姓名");
		columns.add("员工职位");
		columns.add("所属部门");
		columns.add("员工性别");
		columns.add("出生日期");
		columns.add("住址");
		columns.add("手机");
		columns.add("电话");
		columns.add("账号是否有效");
		columns.add("创建日期");
		columns.add("身份证号");
		columns.add("是否开启客服");
		columns.add("客服名");
		columns.add("客服电话");
		columns.add("员工卡号");
	}
	//获得行数
	public int getRowCount(){
		return rowdatas.size();
	}
	//获得列数
	public int getColumnCount(){
		return columns.size();
	}
	//获得单元格的值
	public Object getValueAt(int row,int column){
		
		return ((Vector)rowdatas.get(row)).get(column);
	}
	//获取列名
	public String getColumnName(int column){
		return (String)columns.get(column);
	}
	
	//获取列对应的类型
	public Class getColumnClass(int column){
//		switch(column) {
//		case 
//			return Double.class;
//		}
		return Object.class;
	}
	//设置单元格是否可编辑
	public boolean isCellEditable(int rowIndex,int columnIndex){
		if(columns.size()-1==columnIndex||columns.size()-2==columnIndex){
			return true;
		}
		return false;
	}
	
	public void removeData(int row){
		rowdatas.remove(row);
	}
	
	
	
	//设置单元格的值
	public void setValueAt(Object aValue,int rowIndex,int columnIndex){
		//取出对应的记录
		Vector rowdata = (Vector)rowdatas.get(rowIndex);
		//删除原来的值
		rowdata.remove(columnIndex);
		//添加用户新修改的值
		rowdata.add(columnIndex,aValue);
	}


	public void setRowData(List<TEmployee> temployeeList) {
		rowdatas.clear();
		if(temployeeList != null && temployeeList.size() != 0){
			for(int i = 0;i < temployeeList.size();i++){
				TEmployee temployee = temployeeList.get(i);
				List<Object> row=new Vector<Object>();
				row.add(temployee.getEmployeeID());
				row.add(temployee.getEmployeeSn());
				TRole role=temployee.getTRole();
				if(role!=null&&role.getName()!=null){
					row.add(role.getName());
				}else{
					row.add("普通员工");
				}
				row.add(temployee.getName());
				row.add(temployee.getJob());
				if (temployee.getTDept() == null || temployee.getTDept().getName() == null)
					row.add(null);
				else
					row.add(temployee.getTDept().getName());
				row.add(ApplicationContext.SEX_MAP().get(temployee.getSex()));
				row.add(temployee.getBirthDate());
				row.add(temployee.getAddress());
				row.add(temployee.getMobile());
				row.add(temployee.getPhone());
				if(temployee.isIsValid()){
					row.add("是");
				}else{
					row.add("否");
				}
				row.add(temployee.getHappenTime());
				row.add(temployee.getNationalID());
				if(temployee.isIsClientService()){
					row.add("是");
				}else{
					row.add("否");
				}
				row.add(temployee.getCSName());
				row.add(temployee.getCSMobile());
				row.add(temployee.getCardNum());
				rowdatas.add(row);
			}
		}
	}
	
	public void clear(){
		rowdatas.clear();
	}
}

